package com.lzy.permission.handler;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
import org.springframework.http.server.ServletServerHttpResponse;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

import com.lzy.web.form.JsonResponse4Ext;

/**
 * 验证失败返回json
 * For Ext 登陆
 * @author pwz
 *
 */
public class JsonAuthenticationSuccessHandler implements AuthenticationSuccessHandler {

	public void onAuthenticationSuccess(HttpServletRequest request,
			HttpServletResponse response, Authentication authentication)
			throws IOException, ServletException {
		
		MappingJacksonHttpMessageConverter converter = new MappingJacksonHttpMessageConverter();
		HttpOutputMessage outputMessage = new ServletServerHttpResponse(response);
		
		JsonResponse4Ext ext = new JsonResponse4Ext();
		
		converter.write(ext, MediaType.APPLICATION_JSON, outputMessage);
		
	}
}
